<!--

Saherace - Rent a Car

This page shows the summary of the rental and the customer could confirm
the rental.

-->

<!-- Include the soap client connection and the header area of the website -->
<?php include('includes/header.php'); ?>

<?php

if(isset($_POST['type']))
	$_SESSION['type'] = $_POST['type'];

if($_SESSION['type']  == 'register') {
	
	//Rental with registration	
	if(isset($_POST['register_title']))	 	$_SESSION['register_title'] 	= $_POST['register_title'];
	if(isset($_POST['register_name'])) 		$_SESSION['register_name'] 		= $_POST['register_name'];
	if(isset($_POST['register_surname'])) 	$_SESSION['register_surname'] 	= $_POST['register_surname'];
	if(isset($_POST['register_phone'])) 	$_SESSION['register_phone'] 	= $_POST['register_phone'];
	if(isset($_POST['register_email'])) 	$_SESSION['register_email'] 	= $_POST['register_email'];
	if(isset($_POST['register_birthday'])) 	$_SESSION['register_birthday'] 	= $_POST['register_birthday'];
	if(isset($_POST['register_password'])) 	$_SESSION['register_password'] 	= $_POST['register_password'];

	$params = array('name' 		=> $_SESSION['register_name'],
			'surname' 	=> $_SESSION['register_surname'],
			'title'		=> $_SESSION['register_title'],
			'phone' 	=> $_SESSION['register_phone'],
			'email'		=> $_SESSION['register_email'],
			'birthday' 	=> $_SESSION['register_birthday'],
			'password'	=> $_SESSION['register_password']);

	$registration = $client->insertNewCustomer($params);

	if(!$registration->return) {
		//If login wasn't successful go back to login page
		echo '<script>'.
				'window.location.replace("login.php?register=failed"); '.
			 '</script>';
		exit;
	} else {
		$_SESSION['type'] = '';
		$_SESSION['login'] = 'true';
	}
	
	//if registration was successful show customer id
	$email = array('email'=> $_SESSION['register_email']);
	$customer_id = $client->getCustomerId($email);
	$_SESSION['customer_id'] = $customer_id->return;
	echo '<div style="color: green;">Ihre Registrierung war erfolgreich.</div>';
	echo '<div style="color: red;">Ihre Kundennummer lautet: ' . $_SESSION['customer_id'] . '</div>';
	echo '<div>Bitte notieren Sie sich Ihre Kundennummer, diese ben&ouml;tigen Sie bei Ihrem n&auml;chsten Login.</div>';

} else if($_SESSION['type']  == 'login') {	
	//Rental with login
	if(isset($_POST['customer_id']))
		$_SESSION['customer_id']	= $_POST['customer_id'];
	if(isset($_POST['customer_pwd']))
		$_SESSION['customer_pwd']	= $_POST['customer_pwd'];
		
	$params = array('customer_id' => $_SESSION['customer_id'], 'password' => $_SESSION['customer_pwd']);
	$rentalLogin = $client->rentalLogin($params);	

	if(!$rentalLogin->return) {
		//If login wasn't successful go back to login page
		echo '<script>'.
				'window.location.replace("login.php?login=false"); '.
			 '</script>';
		exit;
		$_SESSION['login'] = 'false';
		unset($_SESSION['customer_id']);
	} else {
		$_SESSION['login'] = 'true';
	}

}

//Get the selected car details
$car_id = array('id' => $_SESSION['car_id']);
$getCarDetails = $client->getCarDetails($car_id);

//Get the customer details
$customer_id = array('customer_id' => $_SESSION['customer_id']);
$getCustomerDetails = $client->getCustomerDetails($customer_id);

//Get the place of the station id
$station_id = array('station_id'=> $_SESSION['start_station'], 
					'start_date'=> $_SESSION['start_date'],
					'end_date'=> $_SESSION['end_date']);
$getStationById = $client->getStationById($station_id);

?>

<!-- List customer attributes -->
<ul data-role="listview" data-inset="true">
	<li data-role="list-divider">Reservierungs&uuml;bersicht</li>
	<li>
		<table>
			<tr>
				<td width="150">Kundennummer:</td>
				<td><?php echo $getCustomerDetails->return->customer_id; ?></td>
			</tr>
			<tr>
				<td width="150">Name:</td>
				<td><?php echo $getCustomerDetails->return->surname . " " . $getCustomerDetails->return->name ; ?></td>
			</tr>
			<tr>
				<td>E-Mail:</td>
				<td><?php echo $getCustomerDetails->return->email; ?></td>
			</tr>
			<tr>
				<td>Telefon:</td>
				<td><?php echo $getCustomerDetails->return->phone; ?></td>
			</tr>
		</table>
	</li>
	<li>
	
	<!-- List rental start and station attributes -->
		<table>
			<tr>
				<td width="150">Anmietung:</td>
				<td><?php $date = new DateTime($_SESSION['start_date']); echo $date->format('d.m.Y H:i') ?> Uhr</td>
			</tr>
			<tr>
				<td></td>
				<td><?php echo $getStationById->return->city; ?></td>
			</tr>
		</table>
	</li>
	<li>
		<table>
			<tr>
				<td width="150">R&uuml;ckgabe:</td>
				<td><?php $date = new DateTime($_SESSION['end_date']); echo $date->format('d.m.Y H:i') ?> Uhr</td>
			</tr>
			<tr>
				<td></td>
				<td><?php echo $getStationById->return->city; ?></td>
			</tr>
		</table>
	</li>
	<li>
	<!-- List car attributes -->
		<table>
			<tr>
				<td colspan="2" style="text-align:center;"><?php echo '<img width="250" src="data:image/jpeg;base64,'.base64_encode($getCarDetails->return->photo).'" />'; ?></td>
			</tr>
			<tr>
				<td width="150">Preis pro Tag:</td>
				<td><?php echo $getCarDetails->return->price; ?> ,- EUR/Tag</td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr>
				<td>Karosserie:</td>
				<td><?php echo $getCarDetails->return->type; ?></td>
			</tr>
			<tr>
				<td>Mindestalter:</td>
				<td><?php echo $getCarDetails->return->minimum_age; ?></td>
			</tr>
			<tr>
				<td>Anzahl Sitze:</td>
				<td><?php echo $getCarDetails->return->number_seats; ?></td>
			</tr>
			<tr>
				<td>Anzahl Türen:</td>
				<td><?php echo $getCarDetails->return->number_doors; ?></td>
			</tr>
			<tr>
				<td>Getriebe:</td>
				<td><?php echo $getCarDetails->return->gear_type; ?></td>
			</tr>
			<tr>
				<td>Klimaanlage:</td>
				<td><?php if($getCarDetails->return->air_conditioner) echo "ja"; else echo "nein"; ?></td>
			</tr>
		</table>
	</li>
</ul>

<!-- button for page to confirm the rental -->
<form action="confirmation_hidden.php" method="POST">
<input type="submit" value="Best&auml;tigen" data-icon="arrow-r" data-iconpos="right" />
<input type="hidden" name="rent" value="true" />
</form>

<!-- Include the footer area of the website -->
<?php include('includes/footer.php'); ?>
